<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <%@include file="../_static/_head.jsp"%>
    <link rel="stylesheet" href="<%=basePath%>H-ui.admin/lib/zTree/v3/css/zTreeStyle/zTreeStyle.css" type="text/css">
</head>
<body>
<article class="page-container">
    <div style="text-align:center">
        <ul id="permissionTree" class="ztree"></ul>
    </div>
    <hr/>
    <div>
        <button class="btn btn-primary radius" type="button" style="display:block;margin:0 auto" onclick="onCheck('${roleId}')">配置</button>
    </div>
</article>
<%@include file="../_static/_foot.jsp"%>
<script type="text/javascript" src="<%=basePath%>H-ui.admin/lib/zTree/v3/js/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="<%=basePath%>H-ui.admin/lib/zTree/v3/js/jquery.ztree.excheck-3.5.js"></script>
<script type="text/javascript">
    var setting = {
        check: {
            chkboxType:{
                "Y" : "p", "N" : "s"
            },
            enable: true
        },
        data: {
            simpleData: {
                enable: true,
                idKey: "id",
                pIdKey: "pid",
                rootPId: "0"
            }
        }
    };

    $(document).ready(function(){
        $.fn.zTree.init($("#permissionTree"), setting, <%=request.getAttribute("zNodes")%>);
    });

    function onCheck(roleId) {
        var treeObj = $.fn.zTree.getZTreeObj("permissionTree"),
            nodes = treeObj.getCheckedNodes(true),
            v = "";

        for (var i = 0; i < nodes.length; i++) {
            v += nodes[i].id + ",";
        }
        layer.confirm('是否确定修改权限', function(index){
            $.ajax({
                url: "/sys/role/permission.json",
                data:{
                    ids:v,
                    roleId:roleId
                },
                method:"POST",
                success: function(data){
                    if (data.code==200){
                        window.parent.location.reload();
                        layer.msg('配置成功!',{icon:1,time:1000});
                        var index = parent.layer.getFrameIndex(window.name);
                        parent.layer.close(index);
                    } else{
                        layer.msg(data.msg,{icon:2,time:1000});
                    }
                }});
        });
    }


</script>
</body>
</html>

